<template>
    <h1>康复理疗信息</h1>
    <a href="/ShowKang">康复理疗列表</a><br>
    <table border="1">
        <tbody>
            <tr>
                <td>项目名称</td>
                <td>
                    <input type="text" v-model="info.name">
                </td>
            </tr>
            <tr>
                <td>项目编码</td>
                <td>
                    <input type="text" v-model="info.bianhao" readonly>
                </td>
            </tr>
            <tr>
                <td>佣金</td>
                <td>
                    <input type="text" v-model="info.price">元
                </td>
            </tr>
            <tr>
                <td>服务人数</td>
                <td>
                    <input type="text" v-model="info.people">人
                </td>
            </tr>
            <tr>
                <td>服务时长</td>
                <td>
                    <input type="text" v-model="info.time">小时
                </td>
            </tr>
            <tr>
                <td>项目说明</td>
                <td>
                    <textarea v-model="info.shuoming">

                    </textarea>
                </td>
            </tr>
            <tr>
                <td>状态</td>
                <td>
                    <input type="radio" :value="true" v-model="info.state">启用
                    <input type="radio" :value="false" v-model="info.state">禁用
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center;">
                    <input type="button" value="保存" @click="Add">
                </td>
            </tr>
        </tbody>
    </table>
</template>

<script setup lang="ts">
import { ref } from "vue";
import axios from "axios";
import { useRouter } from "vue-router";
const router=useRouter();

const info=ref({
    "id": 0,
      "name": "",
      "bianhao": "",
      "price": 0,
      "people": 0,
      "time": 0,
      "shuoming": "",
      "state": true,
      "delete": 0
})

const Add=()=>{
    if(info.value.name==""){
        alert("康复项目标题不能为空")
        return;
    }
    if(info.value.price==0){
        alert("康复项目价格不能为空")
        return;
    }
    if(info.value.people==0){
        alert("康复项目人数不能为空")
        return;
    }
    if(info.value.time==0){
        alert("康复项目时长不能为空")
        return;
    }
    if(info.value.people==3.5){
        alert("康复项目人数必须是整数")
        return;
    }
    if(info.value.time==5.5){
        alert("康复项目时长必须是整数")
        return;
    }

    axios.post("https://localhost:7052/api/Kang/Add",info.value)
    .then(res=>{
        if(res.data>0){
            alert("添加成功")
            router.push("/ShowKang")
        }
        else{
            alert("添加失败")
        }
    })
}

</script>